package com.ufgov.smartclient.component.table;

import javax.swing.JTable;

import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WriteException;

public class DefaultCellFormatPrivoder implements CellFormatPrivoder {

  private WritableCellFormat defaultFormat = null;

  public WritableCellFormat getDefaultCellFormat() throws WriteException {
    if (defaultFormat == null) {
      WritableFont cellFont = createFont();
      defaultFormat = new WritableCellFormat();
      defaultFormat.setFont(cellFont);
      defaultFormat.setWrap(false);
      defaultFormat.setShrinkToFit(true);
      defaultFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
      defaultFormat.setAlignment(Alignment.CENTRE);
      defaultFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
    }
    return defaultFormat;
  }

  protected WritableFont createFont() throws WriteException {
    WritableFont cellFont = new WritableFont(WritableFont.createFont("宋体"));
    cellFont.setPointSize(14);
    return cellFont;
  }

  @Override
  public WritableCellFormat getHeaderCellFormatAt(JTable table)
    throws WriteException {
    return getDefaultCellFormat();
  }

  @Override
  public WritableCellFormat getDataCellFormatAt(int rowIndex, int columnIndex,
    JTable table) throws WriteException {
    return getDefaultCellFormat();
  }

  @Override
  public WritableCellFormat getTotalCellFormatAt(int columnIndex, JTable table)
    throws WriteException {
    return getDefaultCellFormat();
  }

}
